#pragma once
#include "./httplib.h"
#include "searcher.hpp"

const std::string input = "data/raw_html/raw.txt";
const std::string root_path = "./wwwroot";
#define PORT 8080

int main()
{
    ns_searcher::Searcher search;
    search.InitSearcher(input);

    httplib::Server server;
    server.set_base_dir(root_path.c_str());
    server.Get("/s", [&search](const httplib::Request &req, httplib::Response &rsp) {
            if(!req.has_param("word"))
            {
                rsp.set_content("必须要有搜索关键字！","text/plain:charset=utf-8");
                return;
            }

            std::string word = req.get_param_value("word");
            logMessage(DEBUG,"用户在搜索 : %s",word.c_str());
            std::string json_string;
            search.Search(word,&json_string);
            rsp.set_content(json_string,"application/json");
    });

    logMessage(DEBUG,"服务器启动成功,端口号 : %d",PORT);
    server.listen("0.0.0.0",PORT);
    return 0;
}